package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.pojo.User;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from users")
    List<User> userList();
    @Select("select * from users where username=#{username} and password=#{password}")
    List<User> userLogin(User user);
    @Update("update users set last_login_at=#{lastLoginAt} where username=#{username}")
    void setLoginTime(User user);
    @Select("select count(*) from users where username=#{username}")
    Integer usernameUsed(User user);
    @Select("select count(*) from users where email=#{email}")
    Integer emailUsed(User user);
    @Insert("insert into users(username, nickname, email, password, role, locked) values(#{username},#{nickname}, #{email}, #{password}, #{role}, #{locked})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void userRegister(User user);
    @Select("select * from users where id=#{id}")
    User getUserById(Integer id);
//    @Update("update users set password=#{password} where id=#{id}")
    void updateInfo(User user);
    @Delete("delete from users where id=#{id}")
    void delUser(Integer id);
}
